package com.zzh.custom.chess;

import android.util.SparseArray;

import com.zzh.custom.R;

public class PiecesFactory {

    // 初始象棋结构集合
    public static final SparseArray<PiecesBean> createPiecesS() {

        SparseArray<PiecesBean> sparseArray = new SparseArray<>();
        // A方
        sparseArray.put(101, createCar(PiecesBean.PARTY_A, 101));
        sparseArray.put(901, createCar(PiecesBean.PARTY_A, 901));
        sparseArray.put(201, createHorse(PiecesBean.PARTY_A, 201));
        sparseArray.put(801, createHorse(PiecesBean.PARTY_A, 801));
        sparseArray.put(301, createLike(PiecesBean.PARTY_A, 301));
        sparseArray.put(701, createLike(PiecesBean.PARTY_A, 701));
        sparseArray.put(401, createSoldiers(PiecesBean.PARTY_A, 401));
        sparseArray.put(601, createSoldiers(PiecesBean.PARTY_A, 601));
        sparseArray.put(501, createPrinces(PiecesBean.PARTY_A, 501));
        sparseArray.put(203, createGun(PiecesBean.PARTY_A, 203));
        sparseArray.put(803, createGun(PiecesBean.PARTY_A, 803));
        sparseArray.put(104, createPawn(PiecesBean.PARTY_A, 104));
        sparseArray.put(304, createPawn(PiecesBean.PARTY_A, 304));
        sparseArray.put(504, createPawn(PiecesBean.PARTY_A, 504));
        sparseArray.put(704, createPawn(PiecesBean.PARTY_A, 704));
        sparseArray.put(904, createPawn(PiecesBean.PARTY_A, 904));
        // B方
        sparseArray.put(110, createCar(PiecesBean.PARTY_B, 110));
        sparseArray.put(910, createCar(PiecesBean.PARTY_B, 910));
        sparseArray.put(210, createHorse(PiecesBean.PARTY_B, 210));
        sparseArray.put(810, createHorse(PiecesBean.PARTY_B, 810));
        sparseArray.put(310, createLike(PiecesBean.PARTY_B, 310));
        sparseArray.put(710, createLike(PiecesBean.PARTY_B, 710));
        sparseArray.put(410, createSoldiers(PiecesBean.PARTY_B, 410));
        sparseArray.put(610, createSoldiers(PiecesBean.PARTY_B, 610));
        sparseArray.put(510, createPrinces(PiecesBean.PARTY_B, 510));
        sparseArray.put(208, createGun(PiecesBean.PARTY_B, 208));
        sparseArray.put(808, createGun(PiecesBean.PARTY_B, 808));
        sparseArray.put(107, createPawn(PiecesBean.PARTY_B, 107));
        sparseArray.put(307, createPawn(PiecesBean.PARTY_B, 307));
        sparseArray.put(507, createPawn(PiecesBean.PARTY_B, 507));
        sparseArray.put(707, createPawn(PiecesBean.PARTY_B, 707));
        sparseArray.put(907, createPawn(PiecesBean.PARTY_B, 907));

        return sparseArray;
    }


    // 创建卒
    public static final PiecesBean createPawn(int campType, int pointKey) {
        return createPiecesBean("卒", PiecesBean.PAWN, campType, pointKey, campType == PiecesBean.PARTY_A ? R.mipmap.pawn : R.mipmap.pawn_n);
    }

    // 创建炮
    public static final PiecesBean createGun(int campType, int pointKey) {
        return createPiecesBean("炮", PiecesBean.CANNON, campType, pointKey, campType == PiecesBean.PARTY_A ? R.mipmap.cannon : R.mipmap.cannon_n);
    }

    // 创建车
    public static final PiecesBean createCar(int campType, int pointKey) {
        return createPiecesBean("车", PiecesBean.VEHICLE, campType, pointKey, campType == PiecesBean.PARTY_A ? R.mipmap.vehicle : R.mipmap.vehicle_n);
    }

    // 创建马
    public static final PiecesBean createHorse(int campType, int pointKey) {
        return createPiecesBean("马", PiecesBean.HORSE, campType, pointKey, campType == PiecesBean.PARTY_A ? R.mipmap.horse : R.mipmap.horse_n);
    }

    // 创建象
    public static final PiecesBean createLike(int campType, int pointKey) {
        return createPiecesBean("象", PiecesBean.AS, campType, pointKey, campType == PiecesBean.PARTY_A ? R.mipmap.as : R.mipmap.as_n);
    }

    // 创建士
    public static final PiecesBean createSoldiers(int campType, int pointKey) {
        return createPiecesBean("士", PiecesBean.SCHOLAR, campType, pointKey, campType == PiecesBean.PARTY_A ? R.mipmap.scholar : R.mipmap.scholar_n);
    }

    // 创建将
    public static final PiecesBean createPrinces(int campType, int pointKey) {
        return createPiecesBean("将", PiecesBean.TAKE, campType, pointKey, campType == PiecesBean.PARTY_A ? R.mipmap.take : R.mipmap.take_n);
    }

    // 公共创建
    private static final PiecesBean createPiecesBean(String name, int type, int campType, int pointKey, int drawableId) {
        PiecesBean piecesBean = new PiecesBean();
        piecesBean.setCampType(campType);
        piecesBean.setName(name);
        piecesBean.setDrawableId(drawableId);
        piecesBean.setPointKey(pointKey);
        piecesBean.setType(type);
        return piecesBean;
    }


}
